<?php

function is_login($name)
{
    $sess = session($name);
    if (empty($sess)) {
        return false;
    } else {
        return true;
    }
}

function ajax_return($code, $msg, $data = null)
{
    $result = array('code' => $code, 'msg' => $msg);
    if (NULL != $data)
        $result['data'] = $data;
    echo json_encode($result);
    exit(0);
}

function subtext($text, $length)
{
    if (mb_strlen($text) > $length) {
        return mb_substr($text, 0, $length, 'utf8') . '...';
    }
    return $text;
}